home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
byepc300.zip
/
BYESHELL.ZIP
/
SHELL.C
< prev
next >
Wrap
Text File
|
1987-10-24
|
21KB
|
1,030 lines
/*
** File: <shell.c>
**
** Purpose: Security Command Line Processor for BYE-PC
**
** Author: R.E. Starr, Jr.
**
** Date: 12/31/86
**
** Revisons: 1.04 - (03/28/87) Modified caller status word to
** allow up to 16 disk drives in system.
**
** 1.05 - (03/30/87) Modified to check for precsence
** of BYE-PC before calling any external functions.
** This allows SHELL to function without BYE-PC.
**
** 1.06 - (03/31/87) Added 'getdrive()' to read the
** current default drive instead of keeping up
** with it in a storage location.
**
** 1.07 - (04/05/87) Added redirection checking
**
** 1.08 - (05/01/87) Added command line options for
** debugging and status level settings.
**
** 1.09 - (05/01/87) Added missing drive table to map
** out invalid/non-supported drives.
**
** 1.10 - (05/08/87) Modified for byexface ver 2.00
*/
#include <stdio.h> /* std Microsoft C headers */
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <process.h>
#include <signal.h>
#include <string.h>
#include <direct.h>
#include <dos.h>
#include <time.h>
#include "byexface.h" /* BYE-PC interface functions */
/* SHELL configuration section */
/* #define PCURS * define for dos cursor with path name */
#define MAX_DRV 'C' /* max drives in system, 16 max. (A-P) */
#define VER 1 /* SHELL Version# */
#define REV 10 /* SHELL Revision# */
#define BYE_VER 3 /* minimum BYE-PC version# required */
#define BYE_REV 0 /* minimum BYE-PC revision# required */
#define BIT_0 0x0001
#define BIT_1 0x0002
#define BIT_2 0x0004
#define BIT_3 0x0008
#define BIT_4 0x0010
#define BIT_5 0x0020
#define BIT_6 0x0040
#define BIT_7 0x0080
/* function declarations */
void commands(), intrinsic(), extrinsic();
void pset_parms(), pset_flags(), pflags_error();
int binary(), break_handler();
int drv_cmd(), null_cmd(), type_cmd(), time_cmd();
int dos_cmd(), exit_cmd(), cd_cmd(), format_cmd(), dir_cmd();
/* static data declarations */
static char Com_spec[64]; /* file spec of COMMAND.COM */
static char Errors = 0; /* # of persistant Errors */
static char Bye_flg = 1; /* BYE-PC loaded flag */
static char Debug = 0; /* BYE-PC not loaded mode */
static unsigned Cstat = 0; /* caller status level */
static unsigned Csw = 0; /* debug mode status flags */
/* ----------------------- NOTE ----------------------------*/
/* The following table is searched using a binary search */
/* and all strings must be in assending alphabetical order. */
/* ---------------------------------------------------------*/
#define PCMDS (sizeof(cmdpri) / sizeof(struct key))
#define RPATHS (sizeof(rpath) / sizeof(struct paths))
#define IPATHS (sizeof(ipath) / sizeof(struct paths))
#define MDRIVE (sizeof(mdrvs))
/* missing system drives */
char mdrvs[] = /* missing drive map */
{
'D', /* drive D: not supported */
'E', /* drive E: not supported */
};
/* intrinsic command table functions */
struct key
{
char *keyword; /* pointer to intrinsic key words */
int (*key_fxn)(); /* pointer to intrinsic functions */
};
struct key cmdpri[] = /* primary command set */
{
"ASSIGN", null_cmd,
"ATTRIB", null_cmd,
"BACKUP", null_cmd,
"BASIC", null_cmd,
"BASICA", null_cmd,
"BREAK", null_cmd,
"CD", cd_cmd,
"CHDIR", cd_cmd,
"COMMAND", null_cmd,
"COMP", null_cmd,
"COPY", null_cmd,
"CTTY", null_cmd,
"DATE", time_cmd,
"DEL", null_cmd,
"DIR", dir_cmd,
"DISKCOMP", null_cmd,
"DISKCOPY", null_cmd,
"DOS", dos_cmd,
"ERASE", null_cmd,
"EXE2BIN", null_cmd,
"EXIT", exit_cmd,
"FDISK", null_cmd,
"FORMAT", format_cmd,
"GRAFTABL", null_cmd,
"GRAPHICS", null_cmd,
"JOIN", null_cmd,
"KEYBFR", null_cmd,
"KEYBGR", null_cmd,
"KEYBIT", null_cmd,
"KEYBSP", null_cmd,
"KEYBUK", null_cmd,
"LABEL", null_cmd,
"MD", null_cmd,
"MKDIR", null_cmd,
"MODE", null_cmd,
"PATH", null_cmd,
"PRINT", null_cmd,
"PROMPT", null_cmd,
"RD", null_cmd,
"RECOVER", null_cmd,
"REN", null_cmd,
"RESTORE", null_cmd,
"RMDIR", null_cmd,
"SELECT", null_cmd,
"SET", null_cmd,
"SHARE", null_cmd,
"SHELL", null_cmd,
"SYS", null_cmd,
"TIME", time_cmd,
"TREE", null_cmd,
"TYPE", type_cmd,
"VER", null_cmd,
"VERIFY", null_cmd,
"VOL", null_cmd,
};
/* invalid and restricted DOS paths */
struct paths
{
char *path; /* pointer to paths */
};
struct paths ipath[] = /* illegal DOS path names */
{
"SYSTEM",
"DOS",
"XBBS",
};
struct paths rpath[] = /* restriced DOS path names */
{
"UPLOADS",
"PRIVATE",
};
/*
** Function: void main()
**
** Paramters: int argc;
** char *argv[];
**
** Purpose: Main shell calling routine
**
** Return: void
*/
main(argc, argv)
int argc;
char *argv[];
{
int rtn, n;
char *ptr;
char inp_buf[80];
char tmp_buf[80];
extern struct cmdpri;
Debug = 0;
Csw = 0;
pset_parms(argc, argv); /* check cmd line line flags */
if (signal(SIGINT, break_handler) == (int(*)()) -1)
printf("\nWARNING: Can't disable CTRL-BREAK interrupt!\n");
if (rtn = _bye_check(BYE_VER, BYE_REV))
{
if (rtn == 1)
{
Bye_flg = 0;
if (Debug)
printf("\nWARNING: BYE-PC not loaded - 'EXIT' to quit SHELL\n"); /* internal error */
else
exit(1);
}
else
{
printf("\nSHELL ERROR: BYE-PC "); /* internal error */
switch(rtn)
{
case 2:
printf("loaded is the wrong Version!\n");
break;
case 3:
printf("loaded is the wrong Revision!\n");
break;
default:
printf("returned invalid error code!\n");
break;
}
exit(1);
}
}
get_comspec(Com_spec); /* get file spec for COMMAND.COM */
if (Bye_flg)
{
_bye_setbreak(CTRL_BRK); /* now enable ctrl-breaks */
Cstat = _bye_getcsw(); /* get callers status */
}
else
Cstat = (Csw != NULL) ? Csw : 0xff00;
/* since we trap them here */
while(1)
{
if (Bye_flg)
Cstat = _bye_getcsw(); /* reset callers status */
if (!get_cmd(inp_buf, 63)) /* get a line from stdin */
continue;
ptr = strupr(inp_buf); /* make string upper case */
while(*ptr == ' ') /* skip over leading spaces */
*ptr++;
strcpy(inp_buf, ptr); /* remove all leading spaces */
strcpy(tmp_buf, ptr); /* make a copy of input str */
if (tmp_buf[0] == '\0') /* loop if no data entered */
continue;
printf("\n");
if (tmp_buf[1] == ':')
{
if (tmp_buf[2] == '\0')
{
drv_cmd(tmp_buf);
continue;
}
else
{
if (bad_drive(inp_buf)) /* check drive first */
continue;
*ptr++; /* execute on another drive */
*ptr++;
strcpy(tmp_buf, ptr);
}
}
if ((ptr = strchr(tmp_buf, ' ')) != NULL)
*ptr = '\0';
if ((n = binary(tmp_buf, cmdpri, PCMDS)) != EOF)
(*cmdpri[n].key_fxn)(inp_buf); /* do function internally */
else
extrinsic(inp_buf); /* DOS system call. */
}
}
/*
** Function: void extrinsic(input_string)
**
** Parms: char *input_string
**
** Purpose: Passes the string to the system to execute as
** a system command it possible.
**
** Return: void
*/
void extrinsic(input_string)
char *input_string;
{
int status;
if (!(*input_string)) /* any command to try? */
return; /* no, reuturn. */
if (bad_path(input_string, 1)) /* check for bad paths */
return;
Errors = 0; /* reset persistant error ctr */
status = system(input_string);
if (status)
printf("\n[EXEC of COMMAND.COM failed!]\n");
}
/*
** Function: void prompt()
**
** Parms: void
**
** Purpose: Shows the cursor prompt
**
** Return: void
*/
prompt()
{
#ifdef PCURS
char pathbuf[51];
if (getc